﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace KernelWorkflow.Runner.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var workflowHost = new WorkflowServiceHost(typeof(MainWorkflow));

            workflowHost.Description.Behaviors
                .Find<WorkflowRuntimeBehavior>()
                .WorkflowRuntime.WorkflowTerminated +=
                (sender, e) => System.Console.WriteLine("WorkflowTerminated: " + e.Exception.Message);
            workflowHost.Description.Behaviors
                .Find<WorkflowRuntimeBehavior>()
                .WorkflowRuntime.WorkflowCompleted +=
                (sender, e) => System.Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString());

            workflowHost.Open();

            System.Console.ForegroundColor = ConsoleColor.Green;
            System.Console.WriteLine("MainWorkflow is ready.");

            System.Console.ForegroundColor = ConsoleColor.Red;
            System.Console.WriteLine("Press <enter> to exit.");

            System.Console.ResetColor();
            System.Console.ReadLine();

            workflowHost.Close();  
        }
    }
}
